gh-86768: check if fd is seekable in os.lseek on Windows#133137
gh-86768: check if fd is seekable in os.lseek on Windows#133137aisk wants to merge 14 commits intopython:mainfrom
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
It may be slightly simpler if set result to -1 initially.
|
hello, is it the function that is called when doing if yes, I am somewhat concerned about the performance impact of adding a syscall on every call. is it really needed? seek is very heavily used by applications and it is performance sensitive. |
|
For example, you can write a ZIP file to not seekable file. If the output file is seekable, It is unfortunate that this change will add 0.3 microseconds for each |
|
@zooba, could you please take a look? I believe this change should be merged, despite its performance impact. |
|
Why not change My general rule is that I don't like predicting what errors the OS should return. It's weird that it doesn't produce an error here, but I guess it breaks a lot of apps to introduce it (which should also warn us against introducing an error...). But if we have to do extra work for a bool result like |
The Line 655 in cfcfbdd Changing the seekable method for FileIO to check if it's a pipe on Windows is also a solution, but I think the |
Fair, but in that case, I'd prefer we check specifically for a pipe and raise, rather than "anything that isn't disk". It's less disruptive to add new exceptions for specific cases than for negative cases. |
These are the LBYL and EAFP sides of the same problem. Some code uses
Does this work for "CON", "NUL" and " |
Maybe? I think My point is that we should make a list of things that are definitely not seekable and handle those, rather than making a list of things that definitely are seekable and assume that all others should be an error. |
|
According to the On Linux, And what is the correct behavior for FILE_TYPE_UNKNOWN? |
Seems reasonable.
I think allow it to work, so that cases where seeking work aren't blocked. Cases where seeking is an error can return an error if they want, but if they want it to be a no-op like pipes, then they can do that too. |
|
Sorry I missed this PR. Update to only check if it's not pipe, and also updated the implementation in |
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
does this fixes #78961 ? |
|
seems only FILE_TYPE_DISK are seekable |
This change will introduce a performance regression:
Before the change:
After the change:
However I think it's acceptable because we added a check in the implementation and
os.lseekusually won't been called too many times in the real world.